<template>
	<view class="app-bookaccount e-p-20">
		<view class="e-radius-20 bg-white e-p-30">
			<view class="e-p-t-12 e-m-b-20">
				<text class="e-font-30" style="color: #353535;">账号</text>
			</view>
			<view class="app-bookaccount__input e-flex-y-center e-m-b-40">
				<input type="text" placeholder="请输入深文艺术账号" border="none"  v-model="account" style="width: 100%;"/>
			</view>
			<view class="e-p-t-12 e-m-b-20 e-flex e-m-b-60">
				<view class="e-font-30 e-flex-1" style="color: #353535;">类型</view>
				<view class="e-flex-xy-center" @tap="showPicker=true">
					<text v-if="selectType.name">{{selectType.name || ''}}</text>
					<text v-else class="e-m-r-10" style="color: #ccc;">请选择类型</text>
					<image class="img-20" :src="$staticPath('checkin/right_arrow.png')" mode=""></image>
				</view>
			</view>
			
			<view class="app-bookaccount__btn e-flex-xy-center e-m-b-30" @tap="handleBind">
				<text class="c-white e-font-28 w-500">保存并使用</text>
			</view>
		</view>
		<view class="e-flex-xy-center e-p-t-30 e-p-b-20">
			<view class="app-bookaccount__line">
				
			</view>
			<text class="e-font-26 c-999 e-p-l-18 e-p-r-18">账号绑定记录</text>
			<view class="app-bookaccount__line">
				
			</view>
		</view>
		<view class="e-radius-20 bg-white e-p-l-20 e-p-r-20">
			<view class="e-flex-xy-center app-bookaccount__item" v-for="item in list" :key="item.id">
				<view class="c-333 e-font-28 w-600 e-flex-1">{{item.account}}</view>
				<view class="c-333 e-font-28 w-600">{{item.type === 1 ? '提货' :'捡漏'}}</view>
				<!-- <image :src="$staticPath('classify/delete.png')" mode="widthFix" class="img-26" @tap="del(item.id)"></image> -->
			</view>
		</view>
		<e-picker  keyName="name" :show="showPicker" :columns="typeList" @confirm="handlePickerConfirm" @cancel="showPicker = false"></e-picker>
	</view>
</template>

<script>
	import {getSWlist,bindSw,deleteSw} from '@/common/request/api'
	export default {
		data() {
			return {
				list:[],
				account:'',
				typeList:[[{name:'提货',value:1},{name:'捡漏',value:2}]],
				showPicker:false,
				selectType:{}
			}
		},
		onShow() {
			this.getData()
		},
		methods: {
			handlePickerConfirm(e){
				this.selectType = e.value[0]
				this.showPicker = false
			},
			getData() {
				getSWlist({isPage:false}).then(res => {
					this.list = res.rows
				})
			},
			handleBind() {
				if (!this.account) {
					return this.$toastApp('请输入深文艺术账号')
				}
				if (!this.selectType.value) {
					return this.$toastApp('请选择类型')
				}
				bindSw({account:this.account,type:this.selectType.value}).then(res => {
					if (res.code == 200) {
						this.$toastApp('操作成功')
						this.account = ''
						this.getData()
					}
				})
			},
			del(id) {
				const vm = this
				uni.showModal({
					title:'提示',
					content:'确定删除吗？',
					success(res) {
						if (res.confirm) {
							deleteSw(id).then(res => {
								if (res.code == 200) {
									vm.$toastApp('操作成功')
									
									vm.getData()
								}
							})
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	@include appBem_b(bookaccount) {
		background: #F8F8F8;
		@include appBem_e(input) {
			height: 120rpx;
			box-shadow: inset 0px -1rpx 0px 0px #EDEDED;
		}
		@include appBem_e(btn) {
			height: 100rpx;
			background: #4B68E3;
			border-radius: 50rpx;
		}
		@include appBem_e(line) {
			width: 44rpx;
			height: 1rpx;
			background: #D5D5D5;
		}
		@include appBem_e(item) {
			height: 110rpx;
			background: #FFFFFF;
			box-shadow: inset 0px -1rpx 0px 0px #EDEFF3;
		}
	}
</style>